package chapter_18.demo_1;

/**
 * Created by Administrator on 2018/8/7.
 * Lambda 表达式
 */
public class CalculableLambda {

    public static Calculable calculable(char opr) {

        Calculable calculable;

        if (opr == '+') {
            calculable = (int a, int b) -> {
                return a + b;
            };
        } else {
            calculable = (int a, int b) -> {
                return a - b;
            };
        }

        return calculable;
    }

    public static void main(String[] args) {

        int n1 = 10;
        int n2 = 5;

        // 实现加法计算 Calculable 对象
        Calculable calculable1 = calculable('+');
        System.out.printf("%d + %d = %d \n", n1 , n2 , calculable1.calculateInt(n1, n2));
        // 实现减法计算 Calculable 对象
        Calculable calculable2 = calculable('-');
        System.out.printf("%d - %d = %d \n", n1 , n2 , calculable2.calculateInt(n1, n2));

    }
}
